package cn.scw.project.facility.domain.pojo;

import cn.scw.common.constant.FacConsts;
import cn.scw.common.constant.PrintConsts;
import cn.scw.common.exception.CustomException;
import cn.scw.common.utils.StringUtils;
import cn.scw.common.utils.file.FileUploadUtils;
import cn.scw.project.facility.domain.FacPrintOrder;
import lombok.Data;

/**
 * @description:
 * @author: lj
 * @create: 2020-06-20
 **/
@Data
public class PrintSetting {
    /**
     * 设备编号
     */
    private String facilityCode;

    /**
     * 文件
     */
    private String url;

    /**
     * 打印尺寸
     */
    private int size;

    /**
     * 未知
     */
    private int type;

    /**
     * 打印质量
     */
    private String quality;

    /**
     * 进纸器
     */
    private String paper;

    /**
     * 打印颜色
     */
    private String color;

    /**
     * 打印份数
     */
    private int copies;

    /**
     * 打印类型
     */
    private boolean collate;

    /**
     * 文件名称
     */
    private String jobName;

    /**
     * 打印类型
     */
    private String mode;

    public PrintSetting(FacPrintOrder order) {
        // TODO 测试完成移除此判断
//        if (StringUtils.isBlank(order.getFacilityCode())) this.facilityCode = PrintConsts.TEST_FACILITY_CODE;
//        else
        this.facilityCode = order.getFacilityCode();
        if (FacConsts.PRINT_TYPE_PICTURE.equals(order.getType())) {
            this.collate = true;
            this.mode = PrintConsts.PRINT_MODE_PHOTO;
            if ("12".equals(order.getTypeCode())) {
                this.size = PrintConsts.PRINT_SIZE_A4;
                this.type = PrintConsts.PRINT_TYPE_0;
                this.paper = order.getTitle().contains("复印") ? PrintConsts.PRINT_PAPER_FRONT1 : PrintConsts.PRINT_PAPER_REAR;
                this.quality = PrintConsts.PRINT_QUALITY_HIGH;
            } else {
                this.size = PrintConsts.PRINT_SIZE_A6_10;
                this.type = PrintConsts.PRINT_TYPE_11;
                this.paper = PrintConsts.PRINT_PAPER_REAR;
                this.quality = PrintConsts.PRINT_QUALITY_HIGH;
            }
        } else {
            this.collate = false;
            this.mode = PrintConsts.PRINT_MODE_DOC;
            this.size = PrintConsts.PRINT_SIZE_A4;
            this.type = PrintConsts.PRINT_TYPE_0;
            this.paper = PrintConsts.PRINT_PAPER_FRONT1;
            this.quality = PrintConsts.PRINT_QUALITY_NORMAL;
        }
        if (order.isColours()) this.color = PrintConsts.PRINT_COLOR_COLOR;
        else this.color = PrintConsts.PRINT_COLOR_MONO;
        this.copies = order.getCount();
        try {
            this.url = FileUploadUtils.getDefaultBaseDir() + "/" + order.getContent().substring(order.getContent().indexOf("upload/"));
        } catch (Exception e) {
            throw new CustomException("打印内容错误");
        }
        int indexOf = this.url.lastIndexOf("/");
        if (indexOf < 0) indexOf = this.url.lastIndexOf("\\");
        this.jobName = this.url.substring(indexOf);
    }
}
